//
//  DMMessageTimeCell.m
//  HDMainWindow
//
//  Created by apple on 2017/5/5.
//  Copyright © 2017年 com.devin.definesys. All rights reserved.
//

#import "DMMessageTimeCell.h"
#import "NSDate+LLExt.h"
#import "LLColors.h"
#import "LLUtils.h"

#define HorizontalMargin 6
#define VerticalMargin 3

@interface DMMessageTimeCell ()

@property (nonatomic) UILabel *dateLabel;

@end

@implementation DMMessageTimeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.avatarImage.hidden = YES ;
        self.bubbleImage.hidden = YES ;
        
        self.contentView.backgroundColor = kLLBackgroundColor_lightGray;
        
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.font = [UIFont systemFontOfSize:12];
        self.dateLabel.textColor = [UIColor whiteColor];
        self.dateLabel.backgroundColor = kLLBackgroundColor_darkGray;
        self.dateLabel.layer.cornerRadius = 6;
        self.dateLabel.clipsToBounds = YES;
        self.dateLabel.textAlignment = NSTextAlignmentCenter;
        
        [self.contentView addSubview:self.dateLabel];
    }
    
    NSDate *date = [NSDate date];
    self.dateLabel.text = [date timeIntervalBeforeNowLongDescription];
    
    [self layoutContentView];
    
    return self;
}

-(void)setMessageModel:(DMMessageBaseModel *)messageModel {
    [super setMessageModel:messageModel];
    [self layoutContentView];
}

- (void)layoutContentView {
    CGRect frame = CGRectZero;
    frame.size.width = self.dateLabel.intrinsicContentSize.width + 2 * HorizontalMargin;
    frame.size.height = self.dateLabel.intrinsicContentSize.height + 2 * VerticalMargin;
    
    frame.origin.x = (SCREEN_WIDTH - frame.size.width) /2;
    frame.origin.y = (40 - frame.size.height)/2 - 5;
    self.dateLabel.frame = frame;
    
}

+ (CGFloat)heightForModel:(DMMessageBaseModel *) model {
    return 40;
}

@end
